package com.park.controller;

import com.park.common.bean.OrderInputView;
import com.park.common.bean.PageBean;
import com.park.common.bean.ResponseBean;
import com.park.common.exception.MessageException;
import com.park.common.poo.OrderInfo;
import com.park.common.util.JsonUtils;
import com.park.platform.service.ITmOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("order")
public class TmOrderController extends BaseController {

    @Autowired
    private ITmOrderService orderService;

    @RequestMapping("getOrders")
    public String getOrders(OrderInputView orderInputView, Model model){
        try {
            model.addAllAttributes(JsonUtils.fromJson(orderInputView));
            PageBean pageBean = orderService.getOrdersIN(orderInputView);
            super.setPageInfo(model, pageBean);
        }catch (Exception e){
            e.printStackTrace();
        }
        return "Order/OrderList";
    }

    @ResponseBody
    @RequestMapping("newLogistics")
    public ResponseBean newLogistics(OrderInfo orderInfo){
        try{
            orderService.newLogistics(orderInfo);
            return new ResponseBean(true);
        }catch (MessageException e){
            e.printStackTrace();
            return new ResponseBean(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseBean(false);
        }
    }

}
